﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;
using System.Runtime.InteropServices;

namespace PickGold
{
	/// <summary>
	/// 委托调用
	/// </summary>
	/// <typeparam name="TYPE">返回类型</typeparam>
	[ComVisible(true)]
	public interface IDelegate<TYPE> : IDelegate
	{
		/// <summary>
		/// 获取调用有返回委托后的返回值
		/// </summary>
		new TYPE Result { get; }

		/// <summary>
		/// 委托调用
		/// </summary>
		/// <returns>返回值</returns>
		new TYPE Invoke();
	}

	/// <summary>
	/// 委托调用
	/// </summary>
	[ComVisible(true)]
	public interface IDelegate : /*ISynchronizeInvoke, */IDisposable
	{
		/// <summary>
		/// 另外指定执行委托的对象
		/// </summary>
		object Runner { set; get; }

		/// <summary>
		/// 取所有远程托管方法执行申明类型
		/// </summary>
		/// <returns>所有远程托管方法执行申明类型</returns>
		Type[] GetRunnerTypes();

		/// <summary>
		/// 调用委托
		/// </summary>
		/// <returns>有返回的委托返回值</returns>
		object Invoke();

		/// <summary>
		/// 开始一个异步委托调用
		/// </summary>
		/// <param name="callback">异步调用完成委托</param>
		/// <returns>异步操作状态</returns>
		IAsyncResult BeginInvoke(AsyncCallback callback);

		/// <summary>
		/// 开始一个异步委托调用
		/// </summary>
		/// <param name="callback">异步调用完成委托</param>
		/// <param name="object">自定义操作状态</param>
		/// <returns>异步操作状态</returns>
		IAsyncResult BeginInvoke(AsyncCallback callback, object @object);

		/// <summary>
		/// 导步委托调用结束
		/// </summary>
		/// <param name="result">异步操作状态</param>
		/// <returns>调用异常，如果成功则返回空</returns>
		Exception EndInvoke(IAsyncResult result);

		/// <summary>
		/// 取调用有返回委托后的返回值
		/// </summary>
		object Result { get; }

		/// <summary>
		/// 代号
		/// </summary>
		Guid Code { get; set; }

		/// <summary>
		/// 名称
		/// </summary>
		string Name { get; set; }

		/// <summary>
		/// 获取内部委托
		/// </summary>
		Delegate Handler { get; }

		/// <summary>
		/// 获取委托调用参数
		/// </summary>
		object[] Parameters { get; }

		/// <summary>
		/// 获取或设置用户定义的对象，它限定或包含关于委托调用的信息。
		/// </summary>
		object Tag { set; get; }
	}
}
